

#include "atomic_op_asm.h"

ENTRY_NP(_atomic_cas_16)
	mov	x4, x0			/* we need r0 for return value */
1:	ldxrh	w0, [x4]		/* load old value */
	cmp	w0, w1			/*   compare? */
	b.ne	2f
	stxrh	w3, w2, [x4]		/* store new value */
	cbnz	w3, 1b			/*   succeed? nope, try again. */
	dmb	st			/* data memory barrier */
2:	ret				/* return. */
END(_atomic_cas_16)

ATOMIC_OP_ALIAS(atomic_cas_16,_atomic_cas_16)
STRONG_ALIAS(_atomic_cas_short,_atomic_cas_16)
STRONG_ALIAS(_atomic_cas_ushort,_atomic_cas_16)
STRONG_ALIAS(__sync_val_compare_and_swap_2,_atomic_cas_16)
